﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CRS.Core.DataAccess;
using CRS.Core.Entities;
using CRS.Web.UserControls;
using VitCode.Web.UI.WebControls;

namespace CRS.Web.BaseData
{
    public partial class RoomList : System.Web.UI.Page
    {
        private void SetData()
        {
            var acc = new CoreDataAccess();
            try
            {
                var list = acc.Session.CreateQuery("From RoomInfo o Order by o.Name").List();
                foreach (RoomInfo obj in list)
                {
                    var ctl = Page.LoadControl("../UserControls/RoomCtl.ascx");
                    if (ctl is RoomCtl)
                    {
                        var roomCtl = ((RoomCtl)ctl);
                        roomCtl.RoomId = obj.Id.ToString();
                        roomCtl.RoomName = obj.Name;
                        roomCtl.RoomState = obj.State;
                        frm.Controls.Add(roomCtl);
                    }
                }
            }
            finally
            {
                acc.CloseSession();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = -1;
            Response.Write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            //if(!IsPostBack)
                SetData();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            var winEdit = new Window(Page, "房间信息明细");
            winEdit.Width = 420;
            winEdit.Height = 360;
            winEdit.ShowModalDialog("RoomInfoEdit.aspx");
        }
    }
}
